//
//  ZHSetViewController.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 15/12/2.
//  Copyright © 2015年 sgone. All rights reserved.
//

#import "ZHSetViewController.h"
#import "AFNetworking.h"
//展示pickView
#import "HZAreaPickerView.h"

#import "XGMM2ViewController.h"
#import "MBProgressHUD+MJ.h"
#import "Common.h"

@interface ZHSetViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource,HZAreaPickerDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property(nonatomic,strong)  AFHTTPSessionManager *manager;


@property(nonatomic,strong) UITextField *textKHYH;
@property(nonatomic,strong) UITextField *textYHDQ;
@property(nonatomic,strong) UITextField *textSKHM;
@property(nonatomic,strong) UITextField *textSKZH;
@property(nonatomic,strong) UITextField *tetxTXMM;


@property(nonatomic,strong) UITextField *textNMM;
@property(nonatomic,strong) UITextField *textRMM;
@property(nonatomic,strong) UITextField *textNext;


//从网络获取的数据
@property(nonatomic,strong) NSString *bank_account;
@property(nonatomic,strong) NSString *bank_area;
@property(nonatomic,strong) NSString *bank_name;
@property(nonatomic,strong) NSString *payee_name;
@property(nonatomic,strong) NSString *flag;


@property(nonatomic,strong) NSString *NNM;
@property(nonatomic,strong) NSString *RMM;


@property(nonatomic,strong) UIPickerView *bankPickview;
//蒙版
@property(nonatomic,strong) UIView *view3;
@property(nonatomic,strong) NSMutableArray *YHlist;




//地址pickView实现需要
@property(strong,nonatomic)NSString *areaValue;
@property(strong,nonatomic)NSString *cityValue;
//@property(strong,nonatomic)NSString *bankNameValue;
@property(strong,nonatomic)HZAreaPickerView *locatePicker;
//蒙版
@property(strong,nonatomic) UIView *view4;


//键盘操作
//@property(nonatomic,strong) UIButton *doneInKeyboardButton;
//添加数字键盘操作蒙版
@property(nonatomic,strong) UIView *numbaerView;

@property(nonatomic,assign) BOOL boolA;
@property(nonatomic,assign) BOOL boolB;




@end

@implementation ZHSetViewController

@synthesize cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;



//afnetworking网络请求数据
- (AFHTTPSessionManager *)manager
{
    if (_manager == nil) {
        _manager  = [AFHTTPSessionManager manager];
    }
    return _manager;
    
    
}




//进行初始化
-(void)setCityValue:(NSString *)cityValue
{
    if (![_cityValue isEqualToString:cityValue]) {
        _cityValue= cityValue;
        
        //设置城市名字使其显示到界面上
        self.bank_area = cityValue;
        self.textYHDQ.text = self.bank_area;
    }
}



//注册通知viewwillappear键盘
-(void)viewWillAppear:(BOOL)animated



{

    
    
    [super viewWillAppear:animated];
    



}


-(void)viewWillDisappear:(BOOL)animated
{

    


    
////注销键盘显示通知
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    [super viewWillDisappear:animated];




}












- (void)viewDidLoad {
    [super viewDidLoad];
    self.titleLabel.text = @"提现设置";
    self.backBtn.hidden = NO;
    self.rightBut.hidden = YES;
    self.rightBut.titleLabel.font = [UIFont systemFontOfSize:17];
    
    
    self.tableView.scrollEnabled = YES;
  
    
    
    
    self.YHlist = [[NSMutableArray alloc]initWithCapacity:0];
    
    [self sendYH];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        //异步加载数据
        
        [self senAPIXX];
        
    });


    
    
}



#pragma mark 上传到服务器
-(void)rightButClick:(id)sender
{
    
    
    [self.textSKHM resignFirstResponder];
    [self.textSKZH resignFirstResponder];
    
    if (self.textKHYH.text.length == 0) {
        
        [self.view makeToast:@"开户银行不能为空"];
        return;
    }

    if (self.textYHDQ.text.length == 0) {
        [self.view makeToast:@"银行地区不能为空"];
        return;
    }
    if (self.textSKHM.text.length == 0)
    {
    
        [self.view makeToast:@"收款户名不能为空"];
        return;
    
    }
    if (self.textSKZH.text.length == 0) {
        
        [self.view makeToast:@"收款账户不能为空"];
        return;
    }

    if (self.textNMM != nil && self.textRMM != nil) {
        
        if (self.textNMM.text.length == 0) {
           
            [self.view makeToast:@"密码不能为空"];
            return;
            
        }
        
        if (self.textRMM.text.length == 0) {
            
            [self.view makeToast:@"重新输入密码不能为空"];
            return;
        }
        
        
        if (![self.textNMM.text isEqualToString:self.textRMM.text]) {
            
            
            [self.view makeToast:@"前后密码不一致"];
            
            return;
        }

    }
 
    
    
    
    
    [self senAPI2];
    
    
    if ([self.flag intValue] == 0) {

    
    dispatch_async(dispatch_get_main_queue(), ^{
        
      [self sendAPI22];
  
    });
    }
    
    




}



-(void)senAPI2
{

    
    NSString *urlString = [NSString stringWithFormat:@"%@update_account",SERVER_ADDRESS2];
    NSDictionary *parmas = @{@"wTel" : self.dataHandler.phone, @"uToken" : self.dataHandler.uToken , @"bank_name" : self.textKHYH.text , @"bank_area" : self.textYHDQ.text ,  @"payee_name" : self.textSKHM.text , @"bank_account" : self.textSKZH.text};
    
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.manager POST:urlString parameters:parmas success:^(NSURLSessionDataTask *task, id responseObject) {
        
        
        if ([responseObject[@"error_flag"] intValue] == 0) {
            
            
            
            
            
            if ([self.flag intValue] == 0) {
            self.boolA = YES;
            [self boolo];
            }
            else if ([self.flag intValue] == 1)
            {
                
                UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"修改成功" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alter show];
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                
                //返回到上一个页面
                [self.navigationController popViewControllerAnimated:YES];

            
            
            }
            
            
        }
        
        else
        {
            
            [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            NSString *str = [NSString stringWithFormat:@"%@",responseObject[@"result_msg"]];
            UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alter show];
            
        }
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"上传失败" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
        
        
        
    }];




}



-(void)sendAPI22
{
    
    
    NSString *newPassword = @"";
    
    newPassword = md5(self.textNMM.text);
    
    
    
    NSString *urlStr = [NSString stringWithFormat:@"%@modify_apply_passwd",SERVER_ADDRESS2];
    
    NSDictionary *params = @{@"wTel" : self.dataHandler.phone , @"uToken" : self.dataHandler.uToken , @"apply_passwd" : newPassword , @"old_apply_passwd" : @""};
    
    
    
    [self.manager POST:urlStr parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"error_flag"] intValue] == 0) {
            
            
            
            if ([self.flag intValue] == 0) {
                self.boolB = YES;
                [self boolo];
            }

            

            
            
        }
        
        else
        {
        
        
        
        }
        
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        
        
    }];
    


}


#pragma mark 
-(void)boolo
{
    
    if (self.boolA == YES  && self.boolB == YES) {
        
        
        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"修改成功" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
        
        
        //通知前一个页面进行刷新
        [[NSNotificationCenter defaultCenter]postNotificationName:@"zhanghu" object:nil];
        
        
        
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        
        //返回到上一个页面
        [self.navigationController popViewControllerAnimated:YES];
  
        
        
        
    }
    
    





}



#pragma mark 获取银行
-(void)sendYH
{
    NSString *urlString = [NSString stringWithFormat:@"%@get_bank_list",SERVER_ADDRESS];
  
    [self.manager POST:urlString parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"error_flag"] intValue] == 0) {
            
            
            NSArray *array = responseObject[@"data"];
            if (array.count != 0)
            {
            
            self.YHlist = [NSMutableArray arrayWithArray:array];
            
            }
            
//  NSLog(@"hahahhahah  %@",self.YHlist);

            
            
            [self.tableView reloadData];
            
            
        }
        else
        {
                    [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
        
//            NSString *str = [NSString stringWithFormat:@"%@",responseObject[@"result_msg"]];
//            UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//            [alter show];
            
        
        }
        
        
        
        
        
        
        
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
                [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
        
//        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请检查网络!" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//        [alter show];
        
        
        
        
    }];

    
    



}



#pragma mark 获取账户信息
-(void)senAPIXX

{
    
    
    
    
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    NSString *urlStr = [NSString stringWithFormat:@"%@get_account",SERVER_ADDRESS2];
    NSDictionary *params = @{@"wTel" : self.dataHandler.phone , @"uToken" : self.dataHandler.uToken};
    
    
    
    [self.manager POST:urlStr parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
       
        if ([responseObject[@"error_flag"] intValue] == 0) {
         
            if ([responseObject[@"data"][@"account_info"][@"bank_account"]isEqualToString:@"(null)"] || !responseObject[@"data"][@"account_info"][@"bank_account"] ) {
                self.bank_name= @"";
                self.bank_account = @"";
                self.bank_area = @"";
                self.payee_name = @"";
                
            }
            else
            {
            
            
            self.bank_account = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"account_info"][@"bank_account"]];
            self.bank_area = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"account_info"][@"bank_area"]];
            self.bank_name = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"account_info"][@"bank_name"]];
                
                
            self.payee_name = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"account_info"][@"payee_name"]];
            
            }
            self.flag = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"account_info"][@"flag"]];
            
            
            
           
            [self.tableView reloadData];
            [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];

            
        }
        
        else
        {
            
            [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
            NSString *str = [NSString stringWithFormat:@"%@",responseObject[@"result_msg"]];
            UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:str delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alter show];
            
        
        
        
        
        }
        

        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        
        
        
       [MBProgressHUD hideAllHUDsForView:self.tableView animated:YES];
        UIAlertView *alter = [[UIAlertView alloc]initWithTitle:@"提示" message:@"连接网络失败！" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
        [alter show];
        
    }];





}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

//    return 1;
    
    return 3;


}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    
    
    if (section == 0) {
        
        return 2;
    }
    else if (section == 1)
    {
    
        return 2;
    
    }
    
    else
    {
    
        if ([self.flag intValue] == 1) {
            
            return 1;
        }
        
        else
        {
            return 2;
        
        }
        
    
    }
    
    
    
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 50;

}



-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    if (section == 0) {
        
        return 0.001;
    }
    else if (section == 1)
    {
        return 0.001;
    
    }
    else
    {
    
        return 0.001;
    
    }
    
    
}




-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{


    if (section == 0) {
        
        return 10;
        
    }
    else if (section == 1)
    {
        return 10;
    
    }
    else
    {
    
        return 200;
    
    }


}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{

    UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
    view3.backgroundColor = BACKGROUND1;
    
    
    if (section == 2)
    {
     UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((ViewWidth - 160/FDLaOt) /2, 60/FDLaOt, 160/FDLaOt, 44 / FDLaOt)];
    btn.backgroundColor = BenSe_COLOR;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [view3 addSubview:btn];
    btn.titleLabel.font = [UIFont systemFontOfSize:16/FDLaOt];
    btn.layer.cornerRadius = 7.0;
    btn.layer.masksToBounds = YES;
    [btn addTarget:self action:@selector(rightButClick:) forControlEvents:UIControlEventTouchUpInside];
        

    
    if ([self.flag intValue]== 0)
    {
        
        
        [btn setTitle:@"保    存" forState:UIControlStateNormal];
    }
    else if ([self.flag intValue] == 1)
    {
    
       [btn setTitle:@"修    改" forState:UIControlStateNormal];
    
    }
    
    
    }
    
    
    
    return view3;
    
    



}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

     static NSString *CellIdentifier = @"Cell";

    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.font = [UIFont systemFontOfSize:16];
    }
    
    
    
    
    
    
    if (indexPath.section == 0) {
        
    
    
    
    if (indexPath.row == 0)
    {
        
      

       
        cell.textLabel.text = @"开户银行";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if (self.textKHYH == nil) {
       
        
        self.textKHYH = [[UITextField alloc]initWithFrame:CGRectMake(90, 0, ViewWidth-90, 50)];
        self.textKHYH.placeholder = @"请选择开户银行名称";
        self.textKHYH.delegate = self;
        self.textKHYH.font = [UIFont systemFontOfSize:16];
        self.textKHYH.returnKeyType = UIReturnKeyDone;
        self.textKHYH.textColor = [UIColor lightGrayColor];
        self.textKHYH.enabled = NO;
        self.textKHYH.tag = 20;
    
            
        }
        [cell addSubview:self.textKHYH];

        if (self.bank_name.length == 0) {
            
            self.textKHYH.text = @"";
        } else
            
            self.textKHYH.text = self.bank_name;
        
    }
    else if (indexPath.row == 1)
    {
        

    cell.textLabel.text = @"银行地区";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        
        if (self.textYHDQ == nil) {
        self.textYHDQ = [[UITextField alloc]initWithFrame:CGRectMake(90,0 , ViewWidth-90, 50)];
        self.textYHDQ.placeholder = @"请选择开户银行地区";
        self.textYHDQ.delegate = self;
        [cell addSubview:self.textYHDQ];
        self.textYHDQ.font = [UIFont systemFontOfSize:16];
          self.textYHDQ.returnKeyType = UIReturnKeyDone;
        self.textYHDQ.textColor = [UIColor lightGrayColor];
        self.textYHDQ.enabled = NO;
            self.textYHDQ.tag = 21;
   
         
        }
        
        if (self.bank_area.length == 0) {
            
            self.textYHDQ.text = @"";
        } else
            
            self.textYHDQ.text = self.bank_area;
    
    }

    }
    
    else if (indexPath.section == 1)
    {
    
        if (indexPath.row == 0)
        {
            cell.textLabel.text = @"收款户名";
            
            if (self.textSKHM == nil) {
                
                self.textSKHM = [[UITextField alloc]initWithFrame:CGRectMake(90,0 , ViewWidth-90, 50)];
                self.textSKHM.placeholder = @"请填写收款户名";
                self.textSKHM.delegate = self;
                [cell addSubview:self.textSKHM];
                self.textSKHM.font = [UIFont systemFontOfSize:16];
                self.textSKHM.returnKeyType = UIReturnKeyDone;
                self.textSKHM.textColor = [UIColor lightGrayColor];
                self.textSKHM.tag = 22;
 

            }
            
            if (self.payee_name.length == 0) {
                
                self.textSKHM.text = @"";
            } else
                
                self.textSKHM.text = self.payee_name;
            
            
        }
        else if (indexPath.row == 1)
        {
            
            cell.textLabel.text = @"收款账户";
            
            if (self.textSKZH == nil) {
                
                
                self.textSKZH = [[UITextField alloc]initWithFrame:CGRectMake(90,0 , ViewWidth-90, 50)];
                self.textSKZH.placeholder = @"请填写收款账户";
                self.textSKZH.delegate = self;
                [cell addSubview:self.textSKZH];
                self.textSKZH.font = [UIFont systemFontOfSize:16];
                self.textSKZH.returnKeyType = UIReturnKeyDone;
                self.textSKZH.textColor = [UIColor lightGrayColor];
                self.textSKZH.keyboardType = UIKeyboardTypeDecimalPad;
                self.textSKZH.tag = 23;
 
                
                
            }
            if (self.bank_account.length == 0) {
                
                self.textSKZH.text = @"";
            } else
                self.textSKZH.text = self.bank_account;
                    }
    }
    
    else
    {
        
        if ([self.flag intValue] == 0) {
            
           
            [self.textNext removeFromSuperview];
            self.textNext = nil;
          
            
            
           
            
            if (indexPath.row == 0) {
                
                cell.textLabel.text = @"设置密码";
                
                
                if (self.textNMM == nil) {
                    
                self.textNMM = [self textField];
                self.textNMM.placeholder = @"请输入密码";
                [cell addSubview:self.textNMM];
                  
                    
                    self.textNMM.tag = 24;
                    self.textNMM.text = self.NNM;
                }
                
                
                
            }
            else
            {
                if (self.textRMM == nil) {
                cell.textLabel.text = @"重置密码";
                self.textRMM = [self textField];
                self.textRMM.placeholder = @"请再次输入密码";
                [cell addSubview:self.textRMM];
                    
                    
                    self.textRMM.tag = 25;
                    self.textRMM.text = self.RMM;
                    
                }
              

            
            }
            
            

        }
        else if ([self.flag intValue] == 1)
        {
            
            
            [self.textRMM removeFromSuperview];
            [self.textNMM removeFromSuperview];
            self.textRMM = nil;
            self.textNMM = nil;

            

            if (indexPath.row == 0) {
                
                if (self.textNext == nil) {
                cell.textLabel.text = @"提现密码";
                self.textNext = [self textField];
                self.textNext.placeholder = @"修改/设置";

                [cell addSubview:self.textNext];
                self.textNext.enabled = NO;
                
                }
                
            }
        
        
        
        }
    
    
    
    
    }
    
    
    
    
//    else
//    {
//    
//        
//        if ([self.flag intValue] == 1) {
//            
//        cell.textLabel.text = @"提现密码";
//        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//        
//        
//        if (self.tetxTXMM == nil) {
//            
//        
//        self.tetxTXMM  = [[UITextField alloc]initWithFrame:CGRectMake(90,0 , ViewWidth-90, 50)];
//        self.tetxTXMM.placeholder = @"修改/设置";
//        self.tetxTXMM.delegate = self;
//        [cell addSubview:self.tetxTXMM];
//        self.tetxTXMM.font = [UIFont systemFontOfSize:16];
//            self.tetxTXMM.returnKeyType = UIReturnKeyDone;
//            self.tetxTXMM.textColor = [UIColor lightGrayColor];
//        self.tetxTXMM.enabled = NO;
//        }
//        self.tetxTXMM.tag = 24;
//            
//            
//        }
//    
//    }
//    
//    


    
    return cell;



}



-(UITextField *)textField
{


    UITextField *field = [[UITextField alloc]initWithFrame:CGRectMake(90,0 , ViewWidth-90, 50)];
    field.placeholder = @"";
    field.delegate = self;
    field.font = [UIFont systemFontOfSize:16];
    field.returnKeyType = UIReturnKeyDone;
    field.textColor =  [UIColor lightGrayColor];
    field.returnKeyType = UIReturnKeyDone;
    
    return field;


}





#pragma mark pickView进行展示


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    
    
    if (indexPath.section == 0)
    {
    
    if (indexPath.row == 0) {
        
        
        
//        //清除自定义数字键盘
//        doneInKeyboardButton = nil;
//        [doneInKeyboardButton removeFromSuperview];
        [self.textSKZH resignFirstResponder];

        [self.view endEditing:YES];
        
        
        //当银行没有数据的时候进行禁止操作
        
        if (self.YHlist.count == 0) {
            
            
            
            [self.view makeToast:@"获取银行列表数据失败"];
            
            return;
        }
        
        

        
        if (self.bankPickview == nil) {
            
            
            
            
            
            self.bankPickview = [[UIPickerView alloc]initWithFrame:CGRectMake(0, ViewHeight-300, ViewWidth, 300)];
           self.view3 = [[UIView alloc]init];
            
        }
        self.bankPickview.backgroundColor = [UIColor whiteColor];
        self.bankPickview.delegate = self;
        self.bankPickview.dataSource = self;
        self.bankPickview.tag = 100;
        
        if (self.textKHYH.text.length == 0) {
            
            self.textKHYH.text=[self.YHlist objectAtIndex:0];
        }
        
        
        
        self.view3.frame = CGRectMake(0, 64, self.bankPickview.frame.size.width, ViewHeight-64);
        self.view3.backgroundColor = [UIColor clearColor];
        [self.view addSubview:self.view3];
        [self.view3  addSubview:self.bankPickview];
        
        
        //点击空白收回键盘
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tapped4:)];
        [self.view3 addGestureRecognizer:tap];
        
        //使得view与pickView一同出来
        
        [UIView animateWithDuration:0.3 animations:^{
            self.view3.frame = CGRectMake(0,self.view.frame.size.height - self.view3.frame.size.height, self.view3.frame.size.width, self.view3.frame.size.height);
        }];

        
        
    }
    
    else if (indexPath.row == 1)
    {
        
//        
//      doneInKeyboardButton = nil;
//        [doneInKeyboardButton removeFromSuperview];
         [self.textSKZH resignFirstResponder];
        
        [self.view endEditing:YES];
    
        if (self.locatePicker == nil || self.view4 == nil) {
            
            
            self.locatePicker = [[HZAreaPickerView alloc]initWithStyle:HZAreaPickerWithStateAndCity delegate:self];
            
              self.view4 = [[UIView alloc]init];
            
            self.view4.frame = CGRectMake(0, 0, ViewWidth, ViewHeight);
            self.view4.backgroundColor = [UIColor clearColor];
            
            
            self.cityValue = [NSString stringWithFormat:@"北京市 通州区"];
            
            //创建pickview
            self.locatePicker.frame =  CGRectMake(0, ViewHeight-230, ViewWidth,230);
            
            
            [self.view addSubview:self.view4];
            [self.view4 addSubview:self.locatePicker];

            

            
        }
        
    
                //点击空白收回键盘
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tapped5:)];
        [self.view4 addGestureRecognizer:tap];
        
        
        
        
        //使得view与pickView一同出来
        
        [UIView animateWithDuration:0.3 animations:^{

            
            
            self.view4.hidden = NO;
            self.locatePicker.hidden = NO;
        }];
    
    }
    
        
    }
    
    
    
    if (indexPath.section == 2)
    {
        
        if ([self.flag  intValue] == 1) {
        
        
    
        
        [self.textSKZH resignFirstResponder];
        
        
        
        
        XGMM2ViewController *xg2 = [[XGMM2ViewController alloc]initWithNibName:nil bundle:nil];
        
        xg2.flag = self.flag;
        
        [self.navigationController pushViewController:xg2 animated:YES];
    
    
    
    
    }

             
    else
        
    {
    

    
    }
        
        
        

    }
}



#pragma mark 点击空白收回键盘

-(void)Tapped5:(UITapGestureRecognizer*)gestureRecognizer
{
    
    
    [UIView animateWithDuration:0.3
                     animations:^{

                         
                     }
                     completion:^(BOOL finished){

                         
                         [self.view4 setHidden:YES];
                         [self.locatePicker setHidden:YES];
                         
                     }];
    
    
    
    
}




#pragma mark - HZAreaPicker delegate
-(void)pickerDidChaneStatus:(HZAreaPickerView *)picker
{
    if (picker.pickerStyle == HZAreaPickerWithStateAndCityAndDistrict) {
        self.areaValue = [NSString stringWithFormat:@"%@ %@ %@", picker.locate.state, picker.locate.city, picker.locate.district];
    } else{
        
        //这里只显示商户的城市
        self.cityValue = [NSString stringWithFormat:@"%@ %@",picker.locate.state,picker.locate.city];
        
    }
}







#pragma mark 点击空白收回键盘

-(void)Tapped4:(UITapGestureRecognizer*)gestureRecognizer
{
    
    
    [UIView animateWithDuration:0.3
                     animations:^{
                         self.view3.frame = CGRectMake(0, self.view3.frame.origin.y+self.view3.frame.size.height, self.view3.frame.size.width, self.view3.frame.size.height);
                         
                     }
                     completion:^(BOOL finished){
                         [self.view3 removeFromSuperview];
                     }];
    
    
    
    
}





#pragma mark pickView的操作

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if (pickerView.tag == 100) {
        return 1;
    }
    
    return 1;
    
}


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.YHlist.count;
}




-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    
    return 30;
    
}




- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    NSString *str=[self.YHlist objectAtIndex:row];
    
    if (row == 0)
    {
        
        self.bank_name = [self.YHlist objectAtIndex:row];
        self.textKHYH.text = self.bank_name;

    }
    
    
    return str;
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    
//    self.textKHYH.text=[self.YHlist objectAtIndex:row];
    
    self.bank_name = [self.YHlist objectAtIndex:row];
    self.textKHYH.text = self.bank_name;
}



//开始编辑的时候使done Button为Nil
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    
    
    
    if (textField == self.textSKZH   )
    {
        
//        //    初始化数字键盘的“完成”按钮
//        [self configDoneInKeyBoardButton];
        
        if (self.numbaerView == nil) {
            
            self.numbaerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ViewWidth, ViewHeight-64)];
            self.numbaerView.alpha = 0.2;
            self.numbaerView.backgroundColor = [UIColor whiteColor];
            [self.tableView addSubview:self.numbaerView];
            
          
        }
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Tapped:)];
        
        [self.numbaerView addGestureRecognizer:tap];

        
        [UIView animateWithDuration:0.25 animations:^{
            if (self.view.y == 0) {
                self.view.y = -30;
                [textField resignFirstResponder];
            }
        }completion:^(BOOL finished){
            
            self.tableView.scrollEnabled = NO;
            
            
        }];

        
        
        
        

     return YES;
        
    }
    
    
    else if (textField == self.textSKHM )
    {
       
        
//        //清除自定义数字键盘
//        doneInKeyboardButton = nil;
//        [doneInKeyboardButton removeFromSuperview];

        


        return YES;
    
    }
    else
    {
    
        return YES;
    
    }
    
    
    
}



#pragma mark 如果没有没有doneButton的产生就收回就点击空白收回键盘
-(void)Tapped:(UITapGestureRecognizer*)gestureRecognizer
{
    
    
    
    [self.numbaerView removeFromSuperview];
    self.numbaerView = nil;

    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘
    
    
    [UIView animateWithDuration:0.25 animations:^{
        if (self.view.y == -30) {
            self.view.y = 0;

            [self.textSKZH resignFirstResponder];
        
        
        }
    }completion:^(BOOL finished){
        
        self.tableView.scrollEnabled = YES;
        
        
    }];
    

    
}




-(BOOL)textFieldShouldReturn:(UITextField *)textField
{

    [textField resignFirstResponder];
    return YES;

}



-(void)textFieldDidEndEditing:(UITextField *)textField
{
    
    
    if (textField.tag == 20) {
        
        self.bank_name = self.textKHYH.text;
    }
    
    else if (textField.tag == 21)
    {
    
        self.bank_area = self.textYHDQ.text;
    
    }
    else if (textField.tag == 22)
    {
      
        self.payee_name = self.textSKHM.text;
    
    
    }
    else if (textField.tag == 23)
    {
    
        self.bank_account = self.textSKZH.text;
    
    }
    else if (textField.tag == 24)
    {
        
        self.NNM = self.textNMM.text;
    
    
    }
    else if (textField.tag == 25)
    {
    
        self.RMM = self.textRMM.text;
    
    }
    
    
    
        




}

@end
